package br.ufmg.vod.wbr;


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;



public class DomainDocDistribution {
	
	int[] conversionMapDocDomain;
//	int[] numDocsPerDomain;
	private final int numDomain;
	
	protected DomainDocDistribution(int[] conversionMapDocDomain, int numDomain) {
		this.conversionMapDocDomain = conversionMapDocDomain;
//		this.numDocsPerDomain = numDocsPerDomain;
		this.numDomain = numDomain;
	}

	
	
	public static DomainDocDistribution loadDocDistributionMap(String distributionFile) throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream(distributionFile)));
		String line = null;
		int maxDocId= 0;
		int maxDomainId= 0;
		while( (line=in.readLine()) != null){
			String[] s = line.split(" +");
			int docId = Integer.parseInt(s[0]);
			int domainId = Integer.parseInt(s[1]);
			maxDocId = Math.max(maxDocId, docId);
			maxDomainId = Math.max(maxDomainId, domainId);
//			conversionMap[docId] = domainId;
		}
		in.close();
		int[] mapDomainPerDoc = new int[maxDocId+1];
		int numDomain =maxDomainId+1;
		System.out.println(1);
		
		in = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream(distributionFile)));
		line = null;
		while( (line=in.readLine()) != null){
			String[] s = line.split(" +");
			int docId = Integer.parseInt(s[0]);
			int domainId = Integer.parseInt(s[1]);
			mapDomainPerDoc[docId] = domainId;
		}
		in.close();
		System.out.println(2);
		

		return new DomainDocDistribution(mapDomainPerDoc, numDomain);
	}
	
	public static void main(String[] args) throws IOException {
		DomainDocDistribution loadDoaDistributionMap = loadDocDistributionMap(Props.docDistribution);
//		int cdf = 0;
//		for (int i = 0; i < loadDoaDistributionMap.length; i++) {
//			System.err.println(i+" "+ cdf );
//			int[] docs = loadDoaDistributionMap[i];
//			System.out.print(i);
//			for (int j = 0; j < docs.length; j++) {
//				System.out.print(" "+docs[j]);
//			}
//			System.out.println();
//		}
	}



	public int[] getConversionMapDocDomain() {
		return conversionMapDocDomain;
	}



	public int[] getNumDocsPerDomain() {
//		return numDocsPerDomain;
		return null;
	}
	
	public int getNumDomains(){
		return numDomain;
	}



}
